package com.jhgk.jhcee.system.controller;

import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.system.domain.model.SysResourceInfoModel;
import com.jhgk.jhcee.system.service.SysResourceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/26 11:12.
 */
@RestController
@RequestMapping("/resource")
@Api(value = "系统资源", tags = {"系统资源"})
public class SysResourceInfoController {

    @Resource(name = "SysResourceInfoServiceImpl")
    private SysResourceInfoService sysResourceInfoService;

    @GetMapping("/refresh")
    @ApiOperation("刷新系统资源")
    public BasisResultful<Object> refresh() {
        sysResourceInfoService.initResourceRolesMap();
        return BasisResultful.success(BasisResultEnum.SUCCESS);
    }

    @PostMapping("/getResourceListAll")
    @ApiOperation("获取所有资源信息")
    public BasisResultful<Object> getResourceListAll(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.getResourceListAll(model);
    }

    @GetMapping("/getModuleResource")
    @ApiOperation("获取模块下的资源记录")
    public BasisResultful<Object> getModuleResource() {
        return sysResourceInfoService.getModuleResource();
    }

    @PutMapping("/saveResource")
    @ApiOperation("更新保存资源记录")
    public BasisResultful<Object> saveResource(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.saveResource(model);
    }

    @PutMapping("/updateResource")
    @ApiOperation("更新资源记录")
    public BasisResultful<Object> updateResource(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.updateResource(model);
    }

    @PutMapping("/setResourceStatus")
    @ApiOperation("更新资源记录状态")
    public BasisResultful<Object> setResourceStatus(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.setResourceStatus(model.getResourceId(), model.getStatus());
    }

    @PostMapping("/addResource")
    @ApiOperation("新增资源记录")
    public BasisResultful<Object> addResource(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.addResource(model);
    }

    @DeleteMapping("/deleteResource")
    @ApiOperation("物理删除资源记录")
    public BasisResultful<Object> deleteResource(@RequestBody SysResourceInfoModel model) {
        return sysResourceInfoService.deleteResource(model);
    }
}
